$().ready(function(){
	$("input[name=workDays]").blur(function(){
		var workDays=parseFloat($("input[name=workDays]").val());
		var days=parseFloat($("#pWorkDays").html());
		var checkStandard=$("#checkStandard").html();
		checkStandard=checkStandard.replace(/[^0-9]/ig,"");
		var cql=parseFloat(checkStandard.substring(0,2));
		var gzbfb=parseFloat(checkStandard.substring(2));
		//出勤率大于80%绩效奖金500
		if(workDays>days*0.01*cql){
			var basicSalary=parseFloat($("input[name=basicSalary]").val());
			var performance=basicSalary*0.01*gzbfb;
			$("input[name=performanceSalary]").val(performance);
			$("input[name=totalMoney]").val(basicSalary+performance);
		}else{
			var basicSalary=parseFloat($("input[name=basicSalary]").val());
			var performance=0;
			$("input[name=performanceSalary]").val(performance);
			$("input[name=totalMoney]").val(basicSalary+performance);
		}
	});
	//销售额改变时计算提成
	$("input[name=saleroom]").blur(function(){
		//基本工资
		var basicSalary=parseFloat($("input[name=basicSalary]").val());
		//绩效工资
		var performance=parseFloat($("input[name=performanceSalary]").val());
		var saleTarget=$("#saleTarget").html();
		var commissStandard=$("#commissStandard").html();
		saleTarget=saleTarget.replace(/[^0-9]/ig,"");
		commissStandard=commissStandard.replace(/[^0-9]/ig,"");
		var xsbz=parseFloat(saleTarget);
		var tczb=parseFloat(commissStandard);
		var saleroom=parseFloat($("input[name=saleroom]").val());
		//如果销售额大于销售标准
		if(saleroom>xsbz){
			var commissionSalary=(saleroom-xsbz)*tczb*0.01;
			$("input[name=commissionSalary]").val(commissionSalary);
			$("input[name=totalMoney]").val(basicSalary+performance+commissionSalary);
		}else{
			$("input[name=commissionSalary]").val(0);
			$("input[name=totalMoney]").val(basicSalary+performance);
		}
	});
	$("input[name=commissionSalary]").blur(function(){
		var basicSalary=parseFloat($("input[name=basicSalary]").val());
		var performanceSalary=parseFloat($("input[name=performanceSalary]").val());
		var commissionSalary=parseFloat($("input[name=commissionSalary]").val());
		$("input[name=totalMoney]").val(basicSalary+performanceSalary+commissionSalary);
	});
	getSalaryInfo($("select[name=empId]").find("option:selected").val());
	
	$("select[name=empId]").change(function(){
		var empId=$("select[name=empId]").find("option:selected").val();
		getSalaryInfo(empId);
	});
});
function getSalaryInfo(empId){
	$.post($("input:hidden[name=ctx]").val()+"/salaryManage_getPerformance.do",{pempId:empId},function(result){
		var performance=JSON.parse(result);
		$("#position").html(performance.roleName);
		$("input[name=basicSalary]").val(performance.basicSalary);
		$("#checkStandard").html(performance.checkStandard);
		$("#pWorkDays").html(performance.workDays);
		$("#saleTarget").html(performance.saleTarget);
		$("#commissStandard").html(performance.commissStandard);
	});
}
